package com.example.e_comm.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;


@Data
@TableName("roles")
@NoArgsConstructor
@AllArgsConstructor
public class Role {
    @TableId(type = IdType.AUTO)
    private long id;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getRoleKey() {
        return roleKey;
    }

    public void setRoleKey(String roleKey) {
        this.roleKey = roleKey;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Integer getDeleted() {
        return deleted;
    }

    public void setDeleted(Integer deleted) {
        this.deleted = deleted;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }
    public Role(long id, String name, String description, String roleKey) {
        this.id = id;
        this.name = name;
        this.description = description;
        this.roleKey = roleKey;
        this.status = 1;
        this.deleted = 0;
        this.updateTime = LocalDateTime.now();
        this.createTime = LocalDateTime.now();

    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public List<Permission> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<Permission> permissions) {
        this.permissions = permissions;
    }

    private String name;//角色名
    private String description;//描述
    @TableField(value = "role_key")
    private String roleKey;//角色标识，用于权限校验
    private Integer status;
    @TableLogic(value = "0",delval = "1")
    private Integer deleted;//0：没有删除 1:逻辑删除
    @TableField(value = "create_time",fill = FieldFill.INSERT)
    private LocalDateTime createTime= LocalDateTime.now();
    @TableField(value = "update_time",fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime = LocalDateTime.now();
//    关联关系,根据角色进行分配权限
    @TableField(exist = false)
    private List<Permission> permissions;//角色权限列表

}
